package itsm.isperp.module.entity.app;

import itsm.isperp.framework.domain.IUser;
import itsm.isperp.framework.domain.UserStatus;
import itsm.isperp.module.dto.app.AppUserRoleDTO;

import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.beans.Field;
import org.springframework.security.core.GrantedAuthority;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 系统人员实体模型
 * 
 * @author lizx
 * @date 2013-2-17
 * @version V1.0
 */
@Entity
@Table(name = "app_user")
public class AppUser implements IUser {

	/**
	 * 
	 */
	static final long serialVersionUID = 1L;

	@Id
	@Field("id")
	String id;

	@Column
	String name;

	@Column
	String password;

	@Column
	@Field("fullname")
	String fullname;

	@Column
	String gender;
	@Column
  String duty;

	@Column
	protected Date birthday;

	@Column
	String email;

	@Column
	String position;

	@Column
	String tel;

	@Column
	String mobile;

	@Column
	String address;

	@Column
	String photo;

	@Column
	boolean enable;

	@Column
	Integer userType;

	@Column
	String company;

	@Column
	String appDepartmentId;

	@Column
	String status;

	@Column
	String longitude;

	@Column
	String latitude;

	@Column
	long channelId;

	@Column
	String userId;

	@Column
	private String openid;

	@Column
	private String nickname;

	@Column
	private String headimgurl;

	@Column
	String customerId;

	@Column
	String customerName;

	@Column
	String type;
	
	@Column
	String idCard;
	
	@Column
	String bankCardNumber;
	
	@Column
	boolean areCustomer;
	
	@Column
  String birthdayMonth;
	
	@Column
  String birthdayDay;
	
	@Column
  String memo;

	public String getIdCard() {
		return idCard;
	}

	public void setIdCard(String idCard) {
		this.idCard = idCard;
	}

	public String getBankCardNumber() {
		return bankCardNumber;
	}

	public void setBankCardNumber(String bankCardNumber) {
		this.bankCardNumber = bankCardNumber;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public AppUser() {

	}

	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getHeadimgurl() {
		return headimgurl;
	}

	public void setHeadimgurl(String headimgurl) {
		this.headimgurl = headimgurl;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public long getChannelId() {
		return channelId;
	}

	public void setChannelId(long channelId) {
		this.channelId = channelId;
	}

	@Override
	public int hashCode() {
		return this.name.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		AppUser user = (AppUser) obj;
		return this.name.equals(user.getUsername());
	}

	public AppUser(AppUserRoleDTO appUserDTO) {
		this.name = appUserDTO.getName();
		this.fullname = appUserDTO.getFullname();
		this.password = appUserDTO.getPassword();
		this.userType = appUserDTO.getUserType().getValue();

	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFullname() {
		return fullname;
	}

	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}

	public String getAppDepartmentId() {
		return appDepartmentId;
	}

	public void setAppDepartmentId(String appDepartmentId) {
		this.appDepartmentId = appDepartmentId;
	}

	public Integer getUserType() {
		return userType;
	}

	public void setUserType(Integer userType) {
		this.userType = userType;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	@Override
	public String getFirstName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setFirstName(String firstName) {
		this.fullname = firstName;
	}

	@Override
	public void setLastName(String lastName) {
		this.fullname = lastName;
	}

	@Override
	public String getLastName() {
		return this.fullname;
	}

	@JsonIgnore
	Collection<? extends GrantedAuthority> auths;

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return auths;
	}

	public void setAuthorities(Collection<? extends GrantedAuthority> auths) {
		this.auths = auths;
	}

	@Override
	public String getUsername() {
		return this.name;
	}

	// 用户是否过期
	@Override
	public boolean isAccountNonExpired() {
		return this.enable;
	}

	// 用户是否未被锁定
	@Override
	public boolean isAccountNonLocked() {

		return this.enable;
	}

	@Override
	public boolean isCredentialsNonExpired() {

		return this.enable;
	}

	@Override
	public boolean isEnabled() {
		// 是否已启用
		return this.enable;
	}

	@Column
	String degree;

	public String getDegree() {
		return degree;
	}

	public void setDegree(String degree) {
		this.degree = degree;
	}

	@Column
	String school;

	public String getSchool() {
		return school;
	}

	public void setSchool(String school) {
		this.school = school;
	}

	@Column
	String speciality;

	public String getSpeciality() {
		return speciality;
	}

	public void setSpeciality(String speciality) {
		this.speciality = speciality;
	}

	@Column
	String title;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column
	String skills;

	public String getSkills() {
		return skills;
	}

	public void setSkills(String skills) {
		this.skills = skills;
	}

	@Column
	String experience;

	public String getExperience() {
		return experience;
	}

	public void setExperience(String experience) {
		this.experience = experience;
	}

	@Column
	Integer workyears;

	public Integer getWorkyears() {
		return workyears;
	}

	public void setWorkyears(Integer workyears) {
		this.workyears = workyears;
	}

	String[] selectedRoles;

	public String[] getSelectedRoles() {
		return selectedRoles;
	}

	public void setSelectedRoles(String[] selectedRoles) {
		this.selectedRoles = selectedRoles;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@JsonIgnore
	@Override
	public UserStatus getUserStatus() {
		return UserStatus.valueOf(status);
	}

	public String getLongitude() {
		return longitude;
	}

	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

	public String getLatitude() {
		return latitude;
	}

	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}

	@Override
	public boolean isPictureSet() {

		return StringUtils.isNotEmpty(photo);
	}

	public boolean isAreCustomer() {
		return areCustomer;
	}

	public void setAreCustomer(boolean areCustomer) {
		this.areCustomer = areCustomer;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

  public String getBirthdayMonth() {
    return birthdayMonth;
  }

  public String getDuty() {
    return duty;
  }

  public void setDuty(String duty) {
    this.duty = duty;
  }

  public void setBirthdayMonth(String birthdayMonth) {
    this.birthdayMonth = birthdayMonth;
  }

  public String getBirthdayDay() {
    return birthdayDay;
  }

  public void setBirthdayDay(String birthdayDay) {
    this.birthdayDay = birthdayDay;
  }

  public String getMemo() {
    return memo;
  }

  public void setMemo(String memo) {
    this.memo = memo;
  }


	

}